package com.yx.china.controller;

import com.yx.china.project.entities.Payment;
import com.yx.china.project.entities.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@Slf4j
public class PayController {

    @Value("${server.port}")
    private String serverPort;

    public static HashMap<Integer, Payment> hashMap = new HashMap<>();
    static {
        hashMap.put(1,new Payment(1L,"28adsasadsafas5d1as5fad5as31d3as0"));
        hashMap.put(2,new Payment(2L,"4das5d5asda4dad5asda5s3dasd53das0"));
        hashMap.put(3,new Payment(3L,"6ads65d351as3d1as53d1a53d3as13as0"));
    }

    @GetMapping("/pay/{id}")
    public ResponseResult<Payment> paymentSQL(@PathVariable("id") Integer id){
        Payment payment = hashMap.get(id);
        ResponseResult<Payment> result = new ResponseResult(200, "from mysql ,serverPort: " + serverPort,payment);
        log.info("数据查询:"+serverPort);
        return result;
    }
}
